package com.heima.admin.controller;

import com.alibaba.fastjson.JSON;
import com.heima.admin.annotation.OperationFill;
import com.heima.api.admin.IAdminClient;
import com.heima.model.admin.dtos.SensitiveDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmSensitive;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor
@RestController
@Slf4j
public class SensitiveController {

    private final IAdminClient sensitiveClient;

    @OperationFill
    @PostMapping("/api/v1/sensitive/list")
    public PageResponseResult list(@RequestBody SensitiveDto dto){
        log.info("敏感词分页查询:{}",dto);
        return sensitiveClient.list(JSON.toJSONString(dto));
    }

    @OperationFill
    @DeleteMapping("/api/v1/sensitive/del/{id}")
    public ResponseResult deleteById(@PathVariable Integer id){
        log.info("删除敏感词:{}");
        ResponseResult result = sensitiveClient.deleteById(id);
        return result;
    }

    @OperationFill
    @PostMapping("/api/v1/sensitive/save")
    public ResponseResult save(@RequestBody WmSensitive wmSensitive){
        log.info("新增敏感词");
        sensitiveClient.save(wmSensitive);
        return ResponseResult.okResult(null);
    }

    @OperationFill
    @PostMapping("/api/v1/sensitive/update")
    public ResponseResult update(@RequestBody WmSensitive wmSensitive){
        log.info("修改敏感词");
        sensitiveClient.update(wmSensitive);
        return ResponseResult.okResult(null);
    }
}
